<template>
    <div>
        <h1 style="text-align: center;">分类添加</h1>
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="分类名称">
                <el-input v-model="form.catname"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onclick">立即新增</el-button>
                <el-button @click="$router.back()">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { catAdd } from '@/request'
export default {
    data () {
        return {
            form:{
                catname:''
            }
        }
    },
    methods: {
        async onclick(){
            let data = await catAdd(this.form)
            // console.log(data);
            let { error_code,msg } = data
            if(error_code = 200){
                this.$message({
                    message: msg,
                    duration: 1500,
                    type: 'success',
                    onClose: () => {
                        this.$router.push('/cat/list')
                    }
                });
            } else {
                this.$message({
                    message: msg,
                    duration: 1500,
                    type: 'error',
                });
            }
        }
    }
}
</script>

<style>
    
</style>
